package com.myproject.thread.volatiles;

public class DeadLock1 {

    private static Object obj1 = new Object();
    private static Object obj2 = new Object();
    private static volatile boolean flag1 = true;
    private static volatile boolean flag2 = true;

    public static void main(String[] args) {

        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (obj1){
                    flag1=false;
                    while (flag2){}
                    synchronized (obj2){
                    }
                }
            }
        });

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (obj2){
                    flag2=false;
                    while (flag1){}
                    synchronized (obj1){
                    }
                }
            }
        });

        t1.start();
        t2.start();
    }

}
